﻿/*
购物车
*/

function ShoppingCartIndex()
{
    this.urlRoot = ctx + '/ShoppingCart/';

    var InitUi = function () {
        var h = $(window).height();
        //$('#iframe').height(h - 10);
    }();
}


ShoppingCartIndex.prototype.initUserList = function () {
    var This = this;
    var searchUser = $('#searchUser').val();

    var loadUserList = function (userList) {
        var trBody = $('#tBody');
        trBody.empty();
        if (userList.length == 0) {
            trBody.append($('<h6>没有匹配用户</h6>'));
        }

        var getHtml = function (userData) {
            var userImg = '../Resources/mainFrame/img/head.png';
            if (userData.user_img != null) {
                userImg = userData.user_img;
            }

            var h = [];
            h.push('<tr  userId="' + userData.user_id + '">');
            h.push('<td class="client-avatar">');
            h.push('   <img alt="image" src="' + userImg + '">');
            h.push('</td>');
            h.push('<td>');
            h.push('<a class="userNameA" data-toggle="tab" href="#"class="client-link">'+userData.user_name+'</a>');
            h.push('</td>');
            h.push('</tr>');

            return h.join('');
        }

        for (var i in userList) {
            var html = getHtml(userList[i]);
            trBody.append($(html));
        }
    }

    $.post(This.urlRoot + 'UserListData', { userName: searchUser }, function (server) {
        if (server.Statu == 0) {
            loadUserList(server.Data);
        } else {
            layer.alert('获取用户列表失败', {icon:5});
        }
    });
}

ShoppingCartIndex.prototype.bind = function ()
{
    var This = this;

    $('#searchBtn').click(function () {
        This.initUserList();
    });

    $('table').on('click','tr', function () {
        var userId = $(this).attr('userId');
        var url = 'UserShoppingCart?userId='+userId;
        $('#iframe').attr('src',url);
    });
}

$(function () {
    var shopping = new ShoppingCartIndex();
    shopping.bind();
    shopping.initUserList();
});